Skip to content

[Week 6] Solved DICTIONARY - profitjean#193

Open
profitjean wants to merge 1 commit intomainfrom
profitjean/week6-dictionary
Open

[Week 6] Solved DICTIONARY - profitjean#193
profitjean wants to merge 1 commit intomainfrom
profitjean/week6-dictionary

Conversation

@profitjean
Copy link
Collaborator

def dfs(vertex):
    global flag
    visited[vertex] = False
    adj = graph[vertex]
    for node in adj:
        if visited[node] == False:
            flag = False
        elif visited[node] == None:
            dfs(node)
    sequence.append(vertex)
    visited[vertex] = True
# ์ค‘๋žต #
   for vertex in visited.keys():
        if visited[vertex] == None:
            flag = True
            sequence = []
            dfs(vertex)
            if flag:
                answer.extend(sequence)
            else:
                break

๊ทธ๋ž˜ํ”„์˜ ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ ๊ฐ’๋“ค์„ ๋Œ๋ฉด์„œ ์œ„์ƒ์ •๋ ฌ์„ dfs๋กœ ์ˆ˜ํ–‰ํ•˜๊ณ , ๋ฆฌํ„ด๊ฐ’์€ answer ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€ํ•œ๋’ค reverse์‹œ์ผœ์ฃผ์–ด ๊ฐ’์„ ๋„์ถœํ–ˆ์Šต๋‹ˆ๋‹ค

@profitjean profitjean requested a review from Queue-ri March 11, 2022 13:00
@profitjean profitjean self-assigned this Mar 11, 2022
@github-actions
Copy link

AOJI Report

โŒ UH OH...Your code has not been accepted.

๐ŸŽฏ AOJ Result

Judge ID Problem ID Language Result Performance
741741 DICTIONARY py3 ์˜ค๋‹ต 248ms

โš  Performance doesn't match. (ยฑ4ms might be a temporary AOJ error)

๐Ÿ“ข Python code has a wider error range in AOJ.

๐ŸŽฏ Tested Commit

Hash Language File Path Performance
4e2a297 py3 DEF/DICTIONARY/profitjean.py 224ms

๐ŸŽฏ Submission Log

Click here to extend
Request to https://algospot.com/accounts/login/?next=/
<Response [200]>

# AOJI UUID: 642e45b6-4730-4cb9-a230-30f7a1983e42
# This code was submitted by AOJI from https://github.com/Queue-ri/Advanced-Algorithm-Study.
# Please contact [email protected] if there's any problem.

import sys
from collections import defaultdict
input = sys.stdin.readline

def dfs(vertex):
    global flag
    visited[vertex] = False
    adj = graph[vertex]
    for node in adj:
        if visited[node] == False:
            flag = False
        elif visited[node] == None:
            dfs(node)
    sequence.append(vertex)
    visited[vertex] = True


case = int(input().rstrip())
for _ in range(case):
    graph = defaultdict(set)
    N = int(input().rstrip())
    words = []
    visited = {}
    for _ in range(N):
        words.append(input().rstrip())
    # ์ด์ „ ๋ฌธ์ž์—ด๊ณผ ๋น„๊ตํ•˜๋ฉด์„œ ๋‹ค๋ฅด๋‹ค๋ฉด ๊ทธ๋ž˜ํ”„์— ์ถ”๊ฐ€์‹œ์ผœ์ฃผ๊ธฐ
    prev = ""
    for word in words:
        for i in range(min(len(prev), len(word))):
            if prev[i] != word[i]:
                graph[prev[i]].add(word[i])
                visited[prev[i]] = None
                visited[word[i]] = None
                break
        prev = word
    answer = [] #return value
    for vertex in visited.keys():
        if visited[vertex] == None:
            flag = True
            sequence = []
            dfs(vertex)
            if flag:
                answer.extend(sequence)
            else:
                break
    if flag:
        alphabet = [a if a not in answer else "" for a in 'abcdefghijklmnopqrstuvwxyz']
        answer.reverse()
        answer = "".join(answer+alphabet)
        print(answer)
    else:
        print("INVALID")



Request to https://algospot.com/judge/problem/submit/DICTIONARY
<Response [200]>

+----+--------+------------+-------+------+-------+------+--------+--------+
|    |      # | ๋ฌธ์ œ         | ์ œ์ถœ์ž   | ์–ธ์–ด   | ๊ธธ์ด    | ๊ฒฐ๊ณผ   | ์ˆ˜ํ–‰์‹œ๊ฐ„   | ์ œ์ถœ์‹œ๊ฐ„   |
|----+--------+------------+-------+------+-------+------+--------+--------|
|  0 | 741741 | DICTIONARY | 0x10  | py3  | 1.6KB | ์˜ค๋‹ต   | 248ms  | ๋ฐฉ๊ธˆ ์ „   |
|  1 | 741096 | DICTIONARY | 0x10  | py3  | 1.4KB | ์ •๋‹ต   | 204ms  | 1์ฃผ ์ „   |
|  2 | 741094 | DICTIONARY | 0x10  | py3  | 1.4KB | ์ •๋‹ต   | 180ms  | 1์ฃผ ์ „   |
+----+--------+------------+-------+------+-------+------+--------+--------+
----
Parsed: 642e45b6-4730-4cb9-a230-30f7a1983e42 from 741741
----
[AOJ Result]
- Judge ID: 741741
- Problem ID: DICTIONARY
- Language: py3
- Result: ์˜ค๋‹ต
- Performance: 248ms

1.0.0-alpha.4 | Developer | Workflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant